/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package query.parser.entities;

import org.streets.commons.util.StringUtils;
import query.parser.AbstractExpression;
import query.parser.IExpression;

/**
 *
 * @author dzb
 */
public class Alias extends AbstractExpression {
	
	public enum AliasType { None, Implicit, As, Equals }

	private AliasType type;
	private String name;

	public Alias(IExpression parent) {
		super(parent);
		this.type = AliasType.Implicit;
	}

	public String getName() {
		return name;
	}

	public void setName(String n) {
		name = n;
	}


	@Override
	public String getValue() {
		String format = "";
		switch ( type )
		{
			case Implicit:
				format = StringUtils.isNotEmpty( name ) ? String.format( " %s", name ) : "";
				break;

			case Equals:
				format = StringUtils.isNotEmpty( name ) ? String.format( "%s = ", name ) : "";
				break;

			case As:
				format = String.format( " AS %s", name );
				break;
		}
		return format;

	}

}
